Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Cache frequently used read-only data in Application variables

Total Hit ( 5411)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Unlike Session variables, there is only one instance of each Application variable. This means that storing data in an Application variable - including memory-consuming data such as long strings or arrays - doesn't severily impact on system performance (unless you store strings with thousands and thousands of characters, of course).

The ideal candidates for being stored in an Application variable are read-only data, for example the ConnectionString property that you later reuse in any ASP page that accesses the database. Typically, you set this variable in the Application_OnStart event procedure in Global.Asa.

Connection strings aren't the only data that can and should be stored in Application variables: any static data is a potential choice. For example, you might read the names of US states or of world countries from a database table and store them into an array, and then store the array into an Application variable. Or you could store an array with the names of product categories - which can be easily considered as static data.

Better yet, if the stored information is bound to be displayed as HTML text, you might prepare the HTML text in advance, and store it in an Application variable. A good example of this technique is the HTML text for a combo control that stores all the product categories:

Click here to copy the following block
' this code creates a combo control that contains
' the list of product categories, and stores the resulting
' HTML text into the Application("CategoriesHTML") variable


Dim rs, html, index

Set rs = Server.CreateObject("ADODB.Recordset")
' the connection string is already in an Application variable
rs.Open "SELECT cat_name FROM Categories", Application("ConnectionString")

' start creating the Combo control
html = "<SELECT NAME=""Categories"" SIZE=1>"

' add one combobox item for each category in the database table
Do Until rs.EOF
  index = index + 1
  html = html & "<OPTION VALUE=" & CStr(index) & ">" & rs(0) & "</OPTION>"
Loop
' close the html tag and the recordset
html = html & "</SELECT>"
rs.Close

' store in the Application variable
Application.Lock
Application("CategoriesHTML") = html
Application.Unlock

You can store the above code in a separate file, that you can include in Global.asa (after the point where you define the Application("ConnectionString") variable, though.
The flexibility of this approach becomes evident if the data isn't really static, and can sometimes vary during the life of the application. For example, when a new product category is added to the database, you just have to include the same file - immediately after the point where the database has been updated - so that the data in the Application variable is always in sync with the data in the database table.





Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.